package com.ztman.service.work.service.impl;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.ztman.basic.context.ContextUtil;
import com.ztman.service.work.dao.ProcessInfoMapper;
import com.ztman.service.work.dto.ProcessInfoPageQuery;
import com.ztman.service.work.dto.ProcessInfoSaveDTO;
import com.ztman.service.work.dto.ProcessInfoUpdateDTO;
import com.ztman.service.work.entity.ProcessInfo;
import com.ztman.service.work.service.ProcessInfoService;
import com.ztman.basic.base.service.SuperServiceImpl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 业务实现类
 *
 * </p>
 *
 * @author wsd
 * @date 2021-08-23
 */
@Slf4j
@Service
public class ProcessInfoServiceImpl extends SuperServiceImpl<ProcessInfoMapper, ProcessInfo> implements ProcessInfoService {
    @Override
    public IPage<ProcessInfoPageQuery> pageType(IPage<ProcessInfoPageQuery> page, ProcessInfoPageQuery model) {
        return baseMapper.pageType(page,model);
    }

    @Override
    public boolean save(ProcessInfoSaveDTO saveDTO) {
        ProcessInfo processInfo = new ProcessInfo();
        BeanUtils.copyProperties(saveDTO,processInfo);
        processInfo.setCreateTime(LocalDateTime.now());
        processInfo.setCreatedBy(ContextUtil.getUserId());
        processInfo.setDelFlag(false);
        processInfo.setState(true);
        return SqlHelper.retBool(baseMapper.insert(processInfo));
    }

    @Override
    public boolean update(ProcessInfoUpdateDTO updateDTO) {
        ProcessInfo processInfo = new ProcessInfo();
        BeanUtils.copyProperties(updateDTO,processInfo);
        processInfo.setUpdateTime(LocalDateTime.now());
        processInfo.setUpdatedBy(ContextUtil.getUserId());
        return SqlHelper.retBool(baseMapper.updateById(processInfo));
    }

    @Override
    public ProcessInfo getProcessInfoById(Long processId) {
        return baseMapper.getProcessInfoById(processId);
    }


}
